Q. WAP to Enter 5 Numbers and display the Sum ?
#include<stdio.h>
main()
{
int val1,sum=0,i;
printf("Please Enter 5 Numbers:\n");
for(i=0;i<5;i++)
{
scanf("%d",&val1);
sum+=val1;
}
printf("Sum is: %d",sum);
}
Q. WAP to Reverse a three digit Number using simple Logic ?
#include<stdio.h>
main()
{
int a;
printf("Enter a three digit number\n");
scanf("%d",&a);
int p = a % 10;
int y= a / 10;
int q = y % 10;
int o = y / 10;
int r = o % 10;
int c = p * 100 + q * 10 + r * 1;
printf("%d",c);
}
#include<stdio.h>
main()
{
int val1,sum=0,i;
printf("Please Enter 5 Numbers:\n");
for(i=0;i<5;i++)
{
scanf("%d",&val1);
sum+=val1;
}
printf("Sum is: %d",sum);
}
Q. WAP to Reverse a three digit Number using simple Logic ?
#include<stdio.h>
main()
{
int a;
printf("Enter a three digit number\n");
scanf("%d",&a);
int p = a % 10;
int y= a / 10;
int q = y % 10;
int o = y / 10;
int r = o % 10;
int c = p * 100 + q * 10 + r * 1;
printf("%d",c);
}
Q. WAP to Find Sum of N Numbers ?
#include <stdio.h>
main()
{
int N, sum = 0;
printf("Program for sum of all numbers from 0 - N\n");
printf("Enter N: ");
scanf("%d", &N);
sum = N * (N+1) / 2;
printf("The sum of all numbers between 0 and %d is: %d", N, sum);
}
Q. WAP to Display the Table of any Number Entered by user ?
#include<stdio.h>
main()
{
int i,num;
printf("Please Enter the Number:\n");
scanf("%d",&num);
printf("Table of %d is: \n",num);
for(i=1;i<=10;i++)
{
printf("%d * %d = %d\n",num,i,num*i);
}
}
Q. WAP to Reverse any digit Number ?
#include<stdio.h>
main ()
{
int no,r,res;
printf("Enter any value: ");
scanf("%d",&no);
r=res=0;
while(no>0)
{
r=no%10;
no=no/10;
res=(res*10)+r;
}
printf("\nReverse is %d",res);
}