Note 1
##### Take Note:

Take a note while surfing.

##### Note With Ink

Give your Note a Colorful Tag.

##### Easy to Access

Stay on same information and in Sync wherever you are.

Note 2
##### Take Note:

Organize your information,It may take Shape.

##### Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3
##### Take Note:

Don't Let information to miss,Because it take shape

##### Note With Ink

Simple an Easy Way to take a note.

##### Easy to Access

Get the same in next visit.

Take Quiz (Monsoon) Beta Version !!
Do You have Qs. in your Mind ??? Ask it as Qs. or MCQs or create it as polling Live Now !!

321 / 348

Write a program in C using command line argument, take input as diameter of circle and calculate the area of circle.

Input : NA

Output : NA

|  Basics | | | |  Fresher
 
#include <stdio.h>#include <stdlib.h>#define PI 3.142int main(int argc, char * argv[]){    float radius, area;if(argc == 1 ||  argc > 2)      {            printf("Enter the diameter of circle\n");            exit(1);      }    radius = atoi(argv[1]) / 2;    area = PI * radius * radius ;    printf("Area of a circle = %5.2f\n", area);}


Tags:TCS

322 / 348

Write a program to sort an array into two halves, one half ascending and second half descending.

Input : NA

Output : NA

|  Array | | | |  Experience, Fresher
 
<p>#include <stdio.h></p><p>int main(void)<br />{<br />Â Â  Â int a[10], i=0, j=0, n, t;</p><p>Â Â  Â printf ("\n Enter the no. of elements: ");<br />Â Â  Â scanf ("%d",


323 / 348

Write a c program to convert binary to decimal using command line arguments?

Input : NA

Output : NA

|  Basics | | | |  Fresher
 
#include <stdio.h>int main(int argc, char *argv[]){int num,binary,decimal=0,rem,base=1;num=atoi(argv[1]);binary=num;while(num>0){rem=num%2;decimal =rem*base;num=num/10;base=base*2;}printf("%d",decimal);return 0;}


Tags:TCS

324 / 348

Define a macro which gives greatest number out of 3 numbers.

Input : NA

Output : NA

|  Basics | | | |  Fresher
 
#include<stdio.h>

#define Largest(a,b,c)((a>b)?((a>c)?a:c):((b>c)?b:c))

int main()
{
int a,b,c,largest;
printf("Enter 3 numbers: ");
scanf("%d%d%d",&a,&b,&c);
largest=Largest(a,b,c);
printf("\nLargest of the 3 numbers: %d",largest);
return 0;
}



325 / 348

Write a function to implement strcasecmp().

Input : NA

Output : NA

|  Strings | | | |  Fresher
 
<p>#include<stdio.h></p><p>#include<conio.h></p><p>void main()</p><p>{</p><p>char str1="EXAMPLE";</p><p>char str2="example";</p><p>int result;</p><p>result=strcasecmp(str1,str2);</p><p>if(result==0)</p><p>printf("strings are equal");</p><p>else if(result<0)</p><p>printf("%s is less than %s",str1,str2);</p><p>else</p><p>printf("%s is greaterÂ than %s",str1,str2);</p><p>}</p>


326 / 348

Write recursive function for reversing a string.

Input : NA

Output : NA

|  Strings | | | |  Fresher
 
#include<stdio.h>

char* reverseString(char* str);

int main()
{
int i, j, k;
char str[100];
char *rev;
printf("Enter the string: ");
scanf("%s",str);
rev=reverseString(str);
printf("The reversed string is: %s ",rev);
return 0;
}
char* reverseString(char *str)
{
static int i = 0;
static char rev[100];
if(*str)
{
reverseString(str+1);
rev[i++]=*str;
}
return rev;
}



327 / 348

Write a function to implement strncpy using recursion.

Input : NA

Output : NA

|  Strings | | | |  Fresher
 
#include<stdio.h>
#include<string.h>
int main()
{
char s1[100],s2[100];
int n;
printf("Enter the string: ");
scanf("%s",s1);
printf("Enter the no. of characters to be copied: ");
scanf("%d",&n);
printf("String 1: %s ",s1);
printf("String 2 after performing strncpy(): %s",strncpy(s2,s1,n));
return 0;
}


328 / 348

Write a function to check the divisibility by 8.

Input : NA

Output : NA

|  Basics | | | |  Fresher
 
#include<stdio.h>
int main()
{
int n;
printf("Enter the number: ");
scanf("%d",&n);
if(n%8==0)
printf("%d is divisible by 8",n);
else
printf("%d is not divisible by 8",n);
return 0;
}



329 / 348

Write a logic for Matrix multiplication.

Input : NA

Output : NA

|  Array | | | |  Fresher
 
#include<stdio.h>
int main()
{
int m,n,i,j,p,q,k,s=0;
int first[50][50],second[50][50],third[50][50];
printf("\nEnter the no. of rows and coloumns of first matrix: ");
scanf("%d%d",&m,&n);
printf("\nEnter the elements of first matrix: ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&first[i][j]);
}
}
printf("\nEnter the no. of rows and coloumns of second matrix: ");
scanf("%d%d",&p,&q);
if(n!=p)
printf("\nMatrix multiplication not possible!!");
else
{
printf("\nEnter the elements of second matrix: ");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&second[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
for(k=0;k<p;k++)
{
s=s+first[i][k]*second[k][j];
}
third[i][j]=s;
s=0;
}
}
printf("\nProduct of the 2 matrix is:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",third[i][j]);
}
printf("\n");
}
}
}



330 / 348

Find the 2nd largest element in array, without sorting and swap in the middle element.

Input : NA

Output : NA

|  Array | | | |  Fresher
 No Discussion on this question yet!