Write a C program to calculate SQUARE of given number using MACRO.
Get link
Facebook
X
Pinterest
Email
Other Apps
C File =>
/* Write a C program to calculate SQUARE of given number using MACRO. */
#include<stdio.h> #define SQUARE(x) x*x int main() { int n; printf("\n Enter number : "); scanf("%d",&n); printf("\n Square of %d is %d",n,SQUARE(n)); return 0; }
C File => /* Write a program to display the command line arguments in reverse order */ #include<stdio.h> #include<stdlib.h> int main(int argc,char * argv[]) { int i; for(i=argc-1;i>0;i--) printf("\n Argument [%d] is : %s",i,argv[i]); return 0; }
C File=> /* Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average. */ #include<stdio.h> #include<stdlib.h> int main() { int n,i,sum=0; int *ptr; float avg; printf("\n Enter how many integers: "); scanf("%d",&n); ptr=(int*)malloc(n*sizeof(int)); for(i=0;i<n;i++) { printf("\n Enter number%d : ",i+1); scanf("%d",&ptr[i]); sum=sum+ptr[i]; } avg=sum/n; printf("\n Sum of numbers = %d\n",sum); printf(" Average of numbers = %f",avg); return 0 ; }
C File => /* Write a C program to accept names of n cities and search for city named “Pune” */ #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int n,flag=0,i; char str[50][50]; printf("\n Enter how many strings? "); scanf("%d",&n); for(i=0;i<n;i++) { printf("\n Enter String%d : ",i+1); scanf("%s",str[i]); } for(i=0;i<n;i++) { if(strcmp(str[i],"Pune")==0) { flag=1; break; } } if(flag==1) printf("\n Pune is found.."); else printf("\n Pune NOT found.."); return 0; }
Comments
Post a Comment
Please do not enter any spam link in message.