Professional Documents
Culture Documents
C Program Notes For Vintage Academy
C Program Notes For Vintage Academy
'int main()' means that our function needs to return some integer at the
end of the execution and we do so by returning 0 at the end of the program.
0 is the standard for the “successful execution of the program”.
'printf(); ' function is used to print the “character, string, float, integer,
octal, and hexadecimal " values onto the output screen.
'return 0; ' means that the program will execute successfully and did
what it was intended to do.
Code:
#include<stdio.h>
int main()
return 0;
Code:
#include<stdio.h>
I
int main()
printf(" Hello!! world. \n"); // '\n' means new line character (it is a comment)
return 0;
Code:
#include<stdio.h>
int main()
printf(" which help you to develop various application for computer. ");
return 0;
Here, 'int' means integer which stores and display all numbers (except
decimal numbers). We use printf() function with a %d format specifier to
display the value of an integer variable. '+' sign is used an operator for add
two integer value in your program.
code:
#include<stdio.h>
int main()
II
{
int a=5;
int b=35;
int x=a+b;
return 0;
Code:
#include<stdio.h>
int main()
int x=90;
int y=58;
int sub_a=x-y;
int sub_b=y-x;
return 0;
code:
#include<stdio.h>
int main()
III
{
int a=47;
int v=23;
int c=a*v;
return 0;
code:
#include<stdio.h>
int main()
int a=15;
int b=6;
int c=a/b;
return 0;
Code:
#include<stdio.h>
int main()
int a=15;
IV
int b=6;
int c=a%b;
return 0;
Code:
#include<stdio.h>
int main()
int a,b,sum=0;
scanf("%d",&a);
scanf("%d",&b);
sum=a+b;
return 0;
Code:
#include<stdio.h>
int main()
V
{
int a,b;
int sub=0;
scanf("%d%d",&a,&b);
sub=a-b;
return 0;
Code:
#include<stdio.h>
int main()
int a;
int b;
int mult=0;
scanf("%d%d",&a,&b);
mult=a*b;
return 0;
VI
12) A program to add four numbers.
Code:
#include<stdio.h>
int main()
int a,b,c,d,sum;
scanf("%d%d%d%d",&a,&b,&c,&d);
sum=a+b+c+d;
return 0;
Here, 'float' variable is used to store and display whole numbers including
decimal place number also.
Code:
#include<stdio.h>
int main()
float h,b,area=0;
printf("\t--------------------------------------------\n");
VII
scanf("%f",&h);
scanf("%f",&b);
printf("\n\t----------------------------------------");
area=0.5*b*h;
return 0;
Code:
#include<stdio.h>
int main()
float r;
float area=0;
scanf("%f",&r);
area=3.14*r*r;
printf("----------------------------------------------\n");
return 0;
VIII
15) A program to find out the greater number using if...else condition.
Code:
#include<stdio.h>
int main()
int a,b;
scanf("%d%d",&a,&b);
if(a>b)
else
return 0;
Code:
#include<stdio.h>
int main()
int a,b;
IX
printf("Enter any two number : ");
scanf("%d%d",&a,&b);
if(a<b)
else
return 0;
Code:
#include<stdio.h>
int main()
int n;
scanf("%d",&n);
if(n%2 == 0)
X
else
return 0;
18) A program to find out the smallest number among three numbers.
Code:
#include<stdio.h>
int main()
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if((a<b)&&(a<c))
else
if((b<a)&&(b<c))
XI
else
return 0;
19) A program to find out the greatest number among three numbers.
Code:
#include<stdio.h>
int main()
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
else
if((b>a)&&(b>c))
XII
}
else
return 0;
20) A program for find out factorial of a user entered number using 'for'
loop
Code:
#include <stdio.h>
int main()
int n,fact=1,i;
scanf("%d",&n);
fact=fact*i;
return 0;
}
XIII
21) A program for find out factors of a number.
Code:
#include <stdio.h>
int main()
int num, i;
scanf("%d", &num);
if (num % i == 0)
return 0;
Code:
#include <stdio.h>
int main()
XIV
printf("Enter two positive integers: ");
if (n1 % i == 0 && n2 % i == 0)
gcd = i;
return 0;
Code:
#include<stdio.h>
int main()
int p,n,r;
float si,t;
scanf("%d",&p);
scanf("%d",&n);
XV
printf("Enter the interest rate per year : @ ");
scanf("%d",&r);
si=p*n*r/100;
t=p+si;
printf("\n Your payable amount after %d years with interest is : Rs. %f",n,t);
return 0;
24) A program to display the series of first 20 natural number using "while"
or "do.....while" loop.
Code:
#include<stdio.h>
int main()
int i=1;
while(i<=20)
i=i+1;
return 0;
XVI
Or, using "do......while"
Code:
#include<stdio.h>
int main()
int i=1;
do
i=i+1;
}while(i<=20);
return 0;
Code:
#include<stdio.h>
int main()
int i;
for(i=1;i<=50;i=i+2)
printf("%d , ",i);
return 0;
XVII
26) A program to display the even series upto 30.
Code:
#include<stdio.h>
int main()
int n;
for(n=2;n<=30;n=n+2)
printf(", %d",n);
return 0;
Code:
#include<stdio.h>
int main()
int b;
for(b=4;b<=60;b=b+4)
return 0;
Code:
#include<stdio.h>
XVIII
int main()
int c;
for(c=1;c<=40;c=c+2)
printf("\t %d \n",c);
return 0;
Code:
#include<stdio.h>
int main()
int y,sum=0;
for(y=1;y<=10;y++)
printf("%d+",y);
sum=sum+y;
printf("= %d",sum);
return 0;
XIX
30) A program to print the series decremented by 2 each time starting from
20.
Code:
#include<stdio.h>
int main()
int i;
for(i=20;i>=2;i=i-2)
printf("%d, ",i);
return 0;
Code:
#include<stdio.h>
#include<string.h>
int main()
char wds;
wds=getchar(); //getchar() is used for collect input from user as value of wds
XX
printf("\t Your entered Character is : ");
return 0;
Code:
#include<stdio.h>
int main()
puts(name);
return 0;
Code:
#include<stdio.h>
#include<string.h>
int main()
char name[10];
XXI
char address[20];
gets(name);
gets(address);
puts(name);
puts(address);
return 0;
34) A program to print out the message "C program is easy to learn." for
five times.
Code:
#include<stdio.h>
int main()
int i;
for(i=1;i<=5;i++)
return 0;
Code:
#include<stdio.h>
XXII
int main()
int a=205;
float b=205;
return 0;
The ASCII value of 'A' is 65 , 'B' is 66 and so on 'Z' is 90. The ASCII code of
'a' is 97 , 'b' is 98 and so on 'z' is 122.
Code:
#include<stdio.h>
int main()
char alpha='a';
int i=90;
printf("\n i= %d",i);
printf("\n i=%c",i);
XXIII
return 0;
37) A program for find out ASCII code of a user entered character.
Code:
#include<stdio.h>
int main()
char var1;
scanf("%c",&var1);
return 0;
Code:
#include<stdio.h>
#include<string.h>
int main()
char name[20];
int a;
gets(name);
XXIV
a=strlen(name); //strlen(); function calculate character.
return 0;
Code:
#include<stdio.h>
#include<string.h>
int main()
gets(s1);
gets(s2);
strcat(s1,s2);
puts(s1);
return 0;
40) A program which using strcpy() for copying one string to another.
Code:
#include<stdio.h>
#include<string.h>
int main()
XXV
{
char s1[20],s2[20];
gets(s1);
gets(s2);
strcpy(s2,s1);
puts(s2);
return 0;
Code:
#include<stdio.h>
int main()
int i=6;
int j;
for(j=1;j<=10;j++)
return 0;
XXVI
42) A program to display the day name depending on user input using
"if.....else"
Code:
#include<stdio.h>
int main()
int day;
scanf("%d",&day);
if(day == 1)
printf("Monday\n");
else if(day == 2)
printf("Tuesday\n");
else if(day == 3)
printf("Wednesday\n");
else if(day == 4)
printf("Thursday\n");
else if(day == 5)
printf("Friday\n");
else if(day == 6)
printf("Saturday\n");
else if(day == 7)
printf("Sunday\n");
else
43) A program to display the name of day depending on user input using "
switch case ".
Code:
#include<stdio.h>
int main()
int day;
scanf("%d",&day);
switch(day)
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
XXVIII
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
case 7:
printf("Sunday\n");
break;
default:
break;
return 0;
Code:
#include<stdio.h>
int main()
int i,j;
XXIX
printf("%d * %d = %d \n",i,j,i*j);
printf("\n");
return 0;
Code:
#include<stdio.h>
int main()
int a,b,ans;
scanf("%d%d",&a,&b);
ans=(a+b)*(a+b);
return 0;
46) A program to find out that the entered character is vowel or not.
Code:
#include<stdio.h>
int main()
char vowel;
XXX
scanf("%c",&vowel);
switch(vowel)
case 'a':
printf("It is a vowel\n");
break;
case 'e':
printf("It is a vowel\n");
break;
case 'i':
printf("It is a vowel\n");
break;
case 'o':
printf("It is a vowel\n");
break;
case 'u':
printf("It is a vowel\n");
break;
default:
break;
return 0;
XXXI
47) A program to check whether a given year is leap year or not.
Code:
#include<stdio.h>
int main()
int year;
scanf("%d",&year);
if(year%4 == 0)
else
return 0;
XXXII