













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Several C and C++ programs with their respective outputs. The programs cover topics such as simple interest, bigger number among two numbers, printing natural numbers, swapping two numbers, calculating the sum of natural numbers, checking for palindrome numbers, and checking for Armstrong numbers. The programs are written in C and C++ languages and use basic programming concepts such as loops, conditional statements, and variables.
Typology: Summaries
1 / 21
This page cannot be seen from the preview
Don't miss anything!














1. Write a c program simple interest? C-Program: #include<stdio.h> int main() { int p,t,r,si; printf("Enter p,t,r values:"); scanf("%d%d%d",&p,&t,&r); si=ptr/100; printf("si value:%d\n",si); return 0; } Output: Enter p,t,r values: 10 10 si value: C++ -Program: #include
Output: Enter p,t,r values: 10 10 si value:
2. Write a c program bigger number among two numbers? C-Program: #include<stdio.h> int main() { int a,b; printf("enter a values:"); scanf("%d",&a); printf("enter b values:"); scanf("%d",&b); if(a>b) { printf("a is big\n"); } else { printf("b is big\n"); } return 0; } Output: enter a values: enter b values: a is big
printf("Enter a value:"); scanf("%d",&a); printf("Enter b value:"); scanf("%d",&b); sum=a+b; printf("sum:%d\n",sum); return 0; } Output: Enter a value: Enter b value: sum: C++ -Programs: #include
C – Program: #include<stdio.h> int main() { int i,n; printf("enter n value:"); scanf("%d",&n); i=1; while(i<=n) { printf("%d\n",i); i=i+1; } return 0; } Output: enter n value: 1 2 3 4 5 6 7 8 9 10 C++ -Program: #include
int n; printf("enter n value:"); scanf("%d",&n); while(n>=1) { printf("%d\n",n); n=n-1; } return 0; } Output: enter n value: 10 9 8 7 6 5 4 3 2 1 C++ -Program: #include
while(n>=1) { cout<<"\n"<<n; n=n-1; } return 0; } Output: enter n value: 10 9 8 7 6 5 4 3 2 1 6.Write a c program factorial of any number? C- Program: #include<stdio.h> int main() { int i=1,f=1,n; printf("enter a number:"); scanf("%d",&n); while(i<=n) { f=f*i;
int a,b,temp; printf("Before swapping a,b values:"); scanf("%d%d",&a,&b); temp=a; a=b; b=temp; printf("After swapping a=%d\n",a); printf("After swapping b=%d\n",b); } Output: Before swapping a,b values: 3 After swapping a= After swapping b= C++ - Program: #include
After swapping a= After swapping b= 8.Write a c program swap two numbers without using temporary variable? C-Program: #include<stdio.h> void main() { int a,b; printf("Before swapping a,b values:"); scanf("%d%d",&a,&b); a=a+b; b=a-b; a=a-b;; printf("After swapping a=%d\n",a); printf("After swapping b=%d\n",b); } Output: Before swapping a,b values: 3 After swapping a= After swapping b= C++ - Program: #include
using namespace std; int main() { int a,i,Sum=0; cout<<"Enter any number:"; cin>>a; for(i=1;i<=a;i++) { Sum =Sum+i; } cout<<"\nSum of Natural Numbers ="<<Sum; } Output: Enter any number: Sum of Natural Numbers = 10.Write a c program to display fibonacci sequence? C – Program #include <stdio.h> int main() { int n,a=0,b=1,c,i; printf("enter a number:"); scanf("%d",&n); for(i=1;i<=n;i++) { printf("%d\n",a); c=a+b; a=b; b=c; } } Output:
enter a number: 0 1 1 2 3 C++ - Program: #include
rem = n % 10; rev = rev * 10 + rem; n = n/10; } if (temp == rev) cout<<"palindrome"; else cout<<"not a palindrome"; return 0; } Output: Enter an integer: 121 palindrome 12.Write a c program to check whether a given number armstrong number or not? C – Program: #include<stdio.h> int main() { int n,temp,r,sum=0; printf("Enter number:"); scanf("%d",&n); temp=n; while(n>0) { r=n%10; sum=sum+(rrr); n=n/10; } if(temp==sum)
printf("armstrong number\n"); else printf("Not armstrong number\n"); return 0; } Output: Enter number: armstrong number C++ - Program: #include
cin>>n; while (n != 0) { rem = n % 10; rev = rev * 10 + rem; n = n/10; } cout<<"Reverse number ="<<rev; return 0; } Output: Enter an number: 123 Reverse number =
array 1.#include<stdio.h> void main() { int arr[20],i,n; printf("\n ENter N Elements"); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d]",&arr[i]); } printf("The array elements are:\n"); for(i=0;i<n;i++) { printf("array[%d]=%d\n",i,arr[i]); } } 2.#include<stdio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j; printf("Input A - Matrix\n");