Sample C Program

Q. Write a simple C program,in which user entered his name,age through keyboard and display on console?


/*c program to accept name & age from user and display it*/
int main()
 char nam[20];
 int age;
 printf("Enter Your Name : ");
 scnaf("%s",&nam); // gets(nam)
 printf("Enter Your Age : ");
 printf("\nUser Name is %s",nam); 
 /*You also use puts(nam)*/
 printf("\nAnd %s age is %d",nam,age);
 return 0;

       Output of above program : 

Enter your name : JamesBond
Enter your age : 35

And JamesBond age is 35

No comments:

Post a Comment