You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<stdio.h>intmain()
{
inta,b,sum;
printf("Enter the value of first integer: ");
scanf("%d", &a);
printf("Enter the value of second integer: ");
scanf("%d", &b);
sum=a+b;
printf("Sum is %d", sum);
return0;
}
4) Program to find quotient and remainder.
#include<stdio.h>intmain()
{
intdivisor, dividend, quotient, remainder;
printf("Enter the value of divisor: ");
scanf("%d", &divisor);
printf("Enter the value of dividend: ");
scanf("%d", ÷nd);
quotient=dividend/divisor;
remainder=dividend%divisor;
printf("Qoutient is %d\n", quotient);
printf("Remainder is %d", remainder);
return0;
}
5) Program to swap two variables without 3rd variable.
#include<stdio.h>intmain()
{
inta,b;
printf("Enter the value of a = ");
scanf("%d", &a);
printf("Enter the value of b = ");
scanf("%d", &b);
a=a+b;
b=a-b;
a=a-b;
printf("~~~~~~~~~~~~~~~~\nAfter Swap\n~~~~~~~~~~~~~~~~\n");
printf("Value of a = %d\nValue of b = %d", a,b);
return0;
}
6) Program to check even odd number.
#include<stdio.h>intmain()
{
intnumber;
printf("Enter the number: ");
scanf("%d", &number);
if (number % 2==0)
printf("Number is Even");
elseprintf("Number is Odd");
return0;
}
7) Finding greteast of two numbers.
#include<stdio.h>intmain()
{
intnum1, num2;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
if (num1>num2)
printf("First Number is Greatest i.e %d", num1);
elseprintf("Second Number is Greatest i.e %d", num2);
return0;
}
8) Find greatest of three number .
#include<stdio.h>intmain()
{
inta,b,c;
printf("Enter the value of a ");
scanf("%d", &a);
printf("Enter the value of b ");
scanf("%d", &b);
printf("Enter the value of c ");
scanf("%d", &c);
if (a>b)
{
if(a>c)
printf("a is the greatest");
elseprintf("c is the greatest");
}
else
{
if (b>c)
printf("b is the greatest");
elseprintf("c is the greatest");
}
return0;
}
9) Program to assign grade to student according to percentage.
#include<stdio.h>intmain()
{
intmarks;
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nSchema for marks and grades\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nMarks\tGrade\n0-30\tF\n31-50\tD\n51-70\tC\n71-80\tB\n81-90\tA2\n91-100\tA1\n");
printf("Enter is the marks (Out of 100): ");
scanf("%d", &marks);
if (marks>=0)
{
if (marks <= 90)
{
if (marks <= 80)
{
if (marks <= 70)
{
if (marks <= 50)
{
if (marks <= 30)
printf("Grade is F");
elseprintf("Grade is D");
}
elseprintf("Grade is C");
}
elseprintf("Grade is B");
}
elseprintf("Grade is A2");
}
elseprintf("Grade is A1");
}
elseprintf("Invalid Input");
return0;
}
10) Program to print roots of quadratic equation.
#include<stdio.h>#include<math.h>intmain()
{
inta,b,c,root1,root2;
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nSchema of a Quadratic Equation is a(x^2) + b(x) + c = 0\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("Enter is value of a ");
scanf("%d", &a);
printf("Enter is value of b ");
scanf("%d", &b);
printf("Enter is value of c ");
scanf("%d", &c);
root1= ((-b) +sqrt((b*b) - (4*a*c)))/(2*a);
root2= ((-b) -sqrt((b*b) - (4*a*c)))/(2*a);
printf("Roots are %d and %d", root1,root2);
return0;
}
11) Program to check year is leap or not.
#include<stdio.h>intmain()
{
intyear;
printf("Enter the year: ");
scanf("%d", &year);
if (year%4==0)
printf("%d is a Leap Year", year);
elseprintf("%d is not a Leap Year", year);
return0;
}
12) Program to print table of 5.
#include<stdio.h>intmain()
{
intnum,x;
printf("Enter the number of mutiples of 5 you want: ");
scanf("%d", &num);
for (x=1; x<=num; x++)
{
printf("5\t*\t%d\t=\t%d\n", x,x*5);
}
return0;
}
#include<stdio.h>intmain()
{
intnum, reverse=0;
printf("Enter the number: ");
scanf("%d", &num);
while(num!=0)
{
reverse=reverse*10;
reverse=reverse+num%10;
num=num/10;
}
printf("Reverse of the Entered Number is %d", reverse);
return0;
}
15) To check whether number is palindrome or not.
#include<stdio.h>intmain()
{
intnum,original, reverse=0;
printf("Enter the number: ");
scanf("%d", &num);
original=num;
while(num!=0)
{
reverse=reverse*10;
reverse=reverse+num%10;
num=num/10;
}
if (original==reverse)
printf("Number is a palindrome");
elseprintf("Number is not a palindorme");
return0;
}
16) To check whether a number is prime or not.
#include<stdio.h>intmain()
{
intnum, k=0, x;
printf("Enter the number: ");
scanf("%d", &num);
for (x=1; x<=num; x++)
{
if (num%x==0)
{
k++;
}
}
if (k==2)
printf("Number is a Prime Number");
else
{
if (k==1)
printf("Number is neither a prime nor a composite");
elseprintf("Number is not a prime number");
}
}
17) Program to print prime numbers from 1 to 100.
#include<stdio.h>intmain()
{
inti, Number, count;
printf(" Prime Number from 1 to 100 are: \n");
for(Number=1; Number <= 100; Number++)
{
count=0;
for (i=2; i <= Number/2; i++)
{
if(Number%i==0)
{
count++;
break;
}
}
if(count==0&&Number!=1 )
{
printf(" %d ", Number);
}
}
return0;
}
18) Program to check whether a number is armstrong or not.
#include<stdio.h>intmain()
{
intnumber,remainder,sum=0,original_number;
printf("Enter the Number: ");
scanf("%d", &number);
original_number=number;
while(number>0)
{
remainder=number%10;
sum=sum+(remainder*remainder*remainder);
number=number/10;
}
if (original_number==sum)
printf("Number is a Armstrong Number");
elseprintf("Number is not a Amrstrong Number");
return0;
}
21) To find sumof the N natural numbers in an array.
#include<stdio.h>intmain()
{
intarr[1000],n,x,y,sum=0;
printf("Enter the number of elements you want to input(From 1 to 1000): ");
scanf("%d", &n);
for (x=0; x<n; x++)
{
printf("Enter Element %d: ", x+1);
scanf("%d", &arr[x]);
}
for (y=0; y<n; y++)
{
sum+=arr[y];
}
printf("Sum of above array elements is %d", sum);
return0;
}
24) Program to check whether a string is palindrome or not .
#include<stdio.h>#include<string.h>intmain()
{
inta,b,c,shit=0;
charstr[9];
printf("Enter the string you want to check");
scanf("%s", str);
for (a=0; a<strlen(str); a++)
{
if (str[a] !=str[strlen(str) - (a+1)])
{
shit=1;
}
}
if (shit==1)
printf("It is not a palindrome.");
elseprintf("It is a palindrome");
return0;
}
25) Programs to perform basic operations like length of string, string concatenation, sting copy, string compare and string reverse.
#include<stdio.h>#include<string.h>intmain()
{
ints1[10],s2[10],s3[40],i,j;
printf("Enter the string 1 (MAX. is 10 Elements): ");
scanf("%s", s1);
printf("Enter the string 2 (MAX. is 10 Elements): ");
scanf("%s", s2);
if(strcmp(s1,s2)==0)
printf("Entered strings are same\n");
elseprintf("Entered strings are not same\n");
printf("Length of string 1 and string 2 is %d and %d respectively\n", strlen(s1),strlen(s2));
printf("Concatenated string is %s\n", strcat(s1,s2));
printf("New Copied string from string 2 by strcpy() is %s\n", strcpy(s3,s2));
printf("Reverse of string 2 is %s",strrev(s2));
return0;
}
26) Programs to swap two numbers using call by value and call by refernce.
Call by reference
/* Call by reference */#include<stdio.h>voidswap(int*, int*);
intmain() {
intx, y;
printf("Enter the value of x and y\n");
scanf("%d%d",&x,&y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
swap(&x, &y);
printf("After Swapping\nx = %d\ny = %d\n", x, y);
return0;
}
voidswap(int*a, int*b)
{
inttemp;
temp=*b;
*b=*a;
*a=temp;
}
call by value:-
/* Call by value */#include<stdio.h>voidswap(int, int);
intmain() {
intx, y;
printf("Enter the value of x and y\n");
scanf("%d%d",&x,&y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
swap(x, y);
printf("After Swapping\nx = %d\ny = %d\n", x, y);
return0;
}
voidswap(inta, intb) {
inttemp;
temp=b;
b=a;
a=temp;
printf("Values of a and b is %d %d\n",a,b);
}
27) Program to calculate factorial of a number with and without recursion both.
/* Recursion */#include<stdio.h>long long intfactorial(long long intx);
intmain()
{
long intnumber;
printf("Enter the number of which you want to know the factorial: ");
scanf("%d", &number);
printf("Factorial of the Entered Number is %d", factorial(number));
return0;
}
long long intfactorial(long long intx)
{
if (x>=1)
returnx*factorial(x-1);
elsereturn1;
}
#include<stdio.h>intmain()
{
intnumber,factorial=1,x;
printf("Enter the number: ");
scanf("%d", &number);
for (x=1; x<=number; x++)
{
factorial=factorial*x;
}
printf("Factorial of %d is %d", number, factorial);
return0;
}
28) Program to print fibonacci series with and without recursion both.
#include<stdio.h>intfib(intj);
intmain()
{
intn,i,j=0;
printf("Enter the Number of terms you want to print: ");
scanf("%d", &n);
printf("Fibonacci Series upto %d terms are: ", n);
for (i=1; i<=n; i++)
{
printf("%d\n", fib(j));
j++;
}
return0;
}
intfib(intj)
{
if (j==1||j==0)
returnj;
elsereturn (fib(j-1) +fib(j-2));
}
#include<stdio.h>intmain()
{
inti,j,n, f[100000]={0,1};
printf("Enter the Number upto which you want to print the fibonacci seires");
scanf("%d", &n);
for (i=0; i<n; i++)
{
f[i+2] =f[i+1] +f[i];
printf("%d\n", f[i]);
}
}
29) Program to calculate average of 5 numbers using function.
#include<stdio.h>intaverage();
intmain()
{
inta,b,c,d,e;
printf("Enter the 5 values of whom you want to calculate average");
scanf("%d %d %d %d %d", &a,&b,&c,&d,&e);
printf("Average is %d", average(a,b,c,d,e));
return0;
}
intaverage(inta, intb, intc, intd, inte)
{
return ((a+b+c+d+e)/5);
}
30) Program to implement linear serach and binary.
Linear Search Program
#include<stdio.h>intmain()
{
inta[99999],i,j,s,k;
printf("Enter the numbers you want to enter: ");
scanf("%d", &i);
for (j=0; j<i; j++)
{
scanf("%d", &a[j]);
}
printf("Enter the number you want to search");
scanf("%d", &s);
for (k=0; k<i; k++)
{
if (s==a[k])
{
printf("%d is present in this array at %d location of array", s,k+1);
break;
}
}
if (k==i)
printf("%d is not present in this array", s);
return0;
}
Binary Search Program
#include<stdio.h>intmain()
{
intnumber, first, middle, last, search, i, arr[9999];
printf("Enter the value of numbers you want to enter: ");
scanf("%d", &number);
printf("Enter those %d values: \n", number);
for (i=0; i<number; i++)
{
scanf("\n%d", &arr[i]);
}
printf("Enter the number you want to search: ");
scanf("%d", &search);
first=0;
last=number-1;
middle= (first+last)/2;
while(first<=last)
{
if(arr[middle]<search)
first=middle+1;
elseif (arr[middle] ==search)
{
printf("%d is found and present at %d", search, middle+1);
break;
}
elselast=middle-1;
middle= (first+last)/2;
}
if (first>last)
printf("%d is not present in the above list", search);
return0;
}
31) Program to implement bubble sort.
#include<stdio.h>intmain()
{
intarray[100], n, c, d, swap;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c=0; c<n; c++)
scanf("%d", &array[c]);
for (c=0 ; c<n-1; c++)
{
for (d=0 ; d<n-c-1; d++)
{
if (array[d] >array[d+1])
{
swap=array[d];
array[d] =array[d+1];
array[d+1] =swap;
}
}
}
printf("Sorted list in ascending order:\n");
for (c=0; c<n; c++)
printf("%d\n", array[c]);
return0;
}
32) Program to store information of 10 students using array of structures.
#include<stdio.h>structstudent
{
charname[50];
introll;
intage;
intmarks;
charsex;
} s[5];
intmain()
{
inti;
printf("Enter the information of students: \n");
for (i=0; i<5; i++)
{
s[i].roll=i+1;
printf("\nFor Roll Number %d: \n", s[i].roll);
printf("Enter Name: ");
scanf("%s", &s[i].name);
printf("Enter Age: ");
scanf("%d", &s[i].age);
printf("Enter Marks: ");
scanf("%d", &s[i].marks);
printf("Enter the Sex:");
scanf("%s", &s[i].sex);
printf("\n\n");
}
printf("Information Entered is: \n\n");
for (i=0; i<5; i++)
{
printf("\nRoll Number: %d\n", i+1);
printf("Name: %s\n", s[i].name);
printf("Age: %d\n", s[i].age);
printf("Marks: %d\n", s[i].marks);
printf("Sex: %c\n", s[i].sex);
printf("\n\n");
}
return0;
}
33) Programs to compute the transpose of a matrix.
#include<stdio.h>intmain()
{
intm1[3][3]={{1,1,1},{2,2,2},{3,3,3}}, m1t[3][3], i,j;
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
m1t[j][i] =m1[i][j];
}
}
for (j=0; j<3; j++)
{
for (i=0; i<3; i++)
{
printf("%d", m1[i][j]);
}
printf("\n");
}
return0;
}
34) Program to print the address of variable using pointer.
#include<stdio.h>intmain() {
inta;
int*pt;
printf("Pointer Example Program : Print Pointer Address\n");
a=10;
pt=&a;
printf("\n[a ]:Value of A = %d", a);
printf("\n[*pt]:Value of A = %d", *pt);
printf("\n[&a ]:Address of A = %p", &a);
printf("\n[pt ]:Address of A = %p", pt);
printf("\n[&pt]:Address of pt = %p", &pt);
printf("\n[pt ]:Value of pt = %p", pt);
return0;
}