Sunday, 28 August 2011

Sample C Program

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

Ans.

/*c program to accept name & age from user and display it*/
#include<stdio.h>
#include<conio.h>
int main()
{
 char nam[20];
 int age;
 printf("Enter Your Name : ");
 scnaf("%s",&nam); // gets(nam)
 printf("Enter Your Age : ");
 scanf("%d",&age);
 printf("\nUser Name is %s",nam); 
 /*You also use puts(nam)*/
 printf("\nAnd %s age is %d",nam,age);
 getch();
 return 0;
}

       Output of above program : 

Enter your name : JamesBond
Enter your age : 35

And JamesBond age is 35


No comments:

Post a Comment