Aricho IT

Simple C programming Sample Source code

1. This is a simple co program. It will just print a string or a group of words . For borland C compiler you need to use getch() function but for codeblock you can omit getch function from your programs :

#include<stdio.h>
#include<conio,h>

void main()

{

printf(“Hello Wordld”);

return 0;

getch();

}

2. Summation program in C programming language:

#include <stdio.h>
#include<conio.h>
int main() {

int a, b, sum;

printf(“Enter two integers: “);
scanf(“%d %d”, &a, &b);
sum = a+ b;

printf(“%d + %d = %d”,a,b, sum);
return 0;
getch();
}

3. Odd even number checking program in c programming language by using if else conditional statement :

#include <stdio.h>
#include<conio.h>
int main() {

int a, b, sum;

printf(“Enter two integers: “);
scanf(“%d %d”, &a, &b);
sum = a+ b;

printf(“%d + %d = %d”,a,b, sum);
return 0;
getch();
}

4. Grading System program in C programming language by using else if ladder :

#include<stdio.h>
#include<conio.h>

void main()

{

int score;

printf(” Enter your number :”);
scanf(“%d”,&score);

if(score>100)

printf(” You have entered wrong score. Please enter a value between 0 to 100 .”);

else if ((score<=100)&&(score>=90))

printf(” Your Grade is A+”);

else if ((score<90)&&(score>=80))

printf(” Your Grade is A”);

else if ((score<80)&&(score>=70))

printf(” Your Grade is A-“);

else if ((score<70)&&(score>=60))

printf(” Your Grade is B+”);

else if ((score<60)&&(score>=50))

printf(” Your Grade is B”);

else if ((score<50)&&(score>=40))

printf(” Your Grade is c”);

else

printf(” Your are failed”);

getch();

}

5. Grading System program for multiple calculation by using for loop and else if ladder statement :

#include<stdio.h>
#include<conio.h>

void main()

{

int score;
int i, max;

printf(” \n How many times you want to do ? “);
scanf(“%d”,&max);

for(i=1;i<=max;i++)

{

printf(” \n Enter your number :”);
scanf(“%d”,&score);

if(score>100)

printf(” \n You have entered wrong score. Please enter a value between 0 to 100 .”);

else if ((score<=100)&&(score>=90))

printf(” \n Your Grade is A+”);

else if ((score<90)&&(score>=80))

printf(” \n Your Grade is A”);

else if ((score<80)&&(score>=70))

printf(” \n Your Grade is A-“);

else if ((score<70)&&(score>=60))

printf(” \n Your Grade is B+”);

else if ((score<60)&&(score>=50))

printf(” \n Your Grade is B”);

else if ((score<50)&&(score>=40))

printf(” \n Your Grade is c”);

else if ((score<40)&&(score>=0))

printf(” \n You are failed .”);

else

printf(” \n Your have entered an invalid number . Please give a number between 0 to 100.”);

}

}

6 . C programming language switch statement example :

#include<stdio.h>
#include<conio.h>

void main()

{

int a,b ,c,d;

printf(“\n Enter 1 for addition, 2 for subtraction , 3 for multiplication, 4 for divison :”);
scanf(“%d”,&a);

switch(a)

{
case 1:
printf(“\n Enter two numbers:”);
scanf(“%d %d”,&b,&c);
d=b+c;
printf(“\n Result of Addition is :%d”,d);

case 2:
printf(“\n Enter two numbers:”);
scanf(“%d %d”,&b,&c);
d=b-c;
printf(“\n Result of substraction is :%d”,d);

break;

case 3:
printf(“\n Enter two numbers: :”);
scanf(“%d %d”,&b,&c);
d=b*c;
printf(“\n Result of multiplication is :%d”,d);
break;

case 4:
printf(“\n Enter two numbers: :”);
scanf(“%d %d”,&b,&c);
d=b/c;
printf(“\n Result of Division is :%d”,d);
break;

default:

printf(“\n Your input is wrong “);

break;

}

getch();

}

7. C programming language while loop example with source code :

/* If while loop condition satisfied then loop will do work otherwise loop will not work */

#include<stdio.h>
#include<conio.h>

void main()

{

int i=1, a,b,c,d;

printf(“\n Enter 1 if you want to do the calculation: “);
scanf(“%d”,&d);

while((i<=10)&&(d==1))
{
printf(“\n Enter your 1st number:”);
scanf(“%d”,&a);

printf(“\n Enter your 2nd number:”);
scanf(“%d”,&b);
c=a+b;

printf(“\n Result: %d “,c);
}
getch();
}

8. C programming language do while loop or do while statement example with source code :

/* If while loop condition do not satisfy then also  loop will do just one time work then program will exit  */

#include<stdio.h>
#include<conio.h>

void main()

{

int i=1, a,b,c,d;

printf(“\n Enter 1 if you want to do the calculation: “);
scanf(“%d”,&d);

do
{
printf(“\n Enter your 1st number:”);
scanf(“%d”,&a);

printf(“\n Enter your 2nd number:”);
scanf(“%d”,&b);
c=a+b;

printf(“\n Result: %d “,c);
} while((i<=10)&&(d==1));
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Secured By miniOrange